package com.fandy.struts.SqlStatement;

import sun.io.Converters;



public class GoodsInfo {

	public   String GetGoodsByID(com.fandy.struts.Model.GoodsInfo  gi)
	{
		return "select * from GoodsInfo where "+com.fandy.struts.Meta.GoodsInfo.getGoodsid()+"= "+gi.getGoodsid();
	}
	
	public   String GetGoodsByID(int  gi)
	{
		return "select * from GoodsInfo where "+com.fandy.struts.Meta.GoodsInfo.getGoodsid()+"= "+gi;
	}
	
	public   String GetAllGoodsInfo()
	{
		return "select * from GoodsInfo";
	}
	
	
	public   String search(String  KeyWord)
	{
		String sqlstm = "select * from GoodsInfo where " ;
		
		String[] str =  KeyWord.split(" ");
		
		for (String string : str) {
			
			try
			{
				int i = Integer.parseInt(string);				
				sqlstm += com.fandy.struts.Meta.GoodsInfo.getGoodsid() + "= '" + i + "' or " ;
			
			}
			catch( Exception e )
			{
				sqlstm += com.fandy.struts.Meta.GoodsInfo.getSize() + "= '" + string + "' or " ;
				sqlstm += com.fandy.struts.Meta.GoodsInfo.getBrand() + "= '" + string + "' or " ;
				sqlstm += com.fandy.struts.Meta.GoodsInfo.getOrigin() + "= '" + string + "' or " ;
				
				sqlstm += com.fandy.struts.Meta.GoodsInfo.getType() + "= '" + string + "' or " ;
				sqlstm += com.fandy.struts.Meta.GoodsInfo.getUnit() + "= '" + string + "'or " ;			
			}
						
		}
		
		sqlstm += " 1=0 " ;
		
		return  sqlstm;
	}
	
	
	public String Add(com.fandy.struts.Model.GoodsInfo gi)
	{
		
		return "insert into GoodsInfo values ("
		+ "'" + gi.getBrand()+"',"		 
		+ "'" +gi.getImage()+"',"
		+ "'"  + gi.getImage() + "',"
		+ "'"  + gi.getOrigin() + "',"
		+ "'"  + gi.getProfit() + "',"
		+ "'"  + gi.getSize() + "',"
		+ "'"  + gi.getType()+ "'"
		+ "'"  + gi.getUnit()+ "'"		
		+")"
		;
		
	}
	
	
	public   String UpdatebyID(int GoodsID,com.fandy.struts.Model.GoodsInfo gi)
	{
		return "update GoodsInfo set "+com.fandy.struts.Meta.GoodsInfo.getBrand()
		+"='" + gi.getBrand()+"',"		 
		+com.fandy.struts.Meta.GoodsInfo.getImage()+"='" +gi.getImage()+"',"
		+com.fandy.struts.Meta.GoodsInfo.getOrigin() + "='"  + gi.getOrigin() + "',"
		+com.fandy.struts.Meta.GoodsInfo.getProfit() + "='"  + gi.getProfit() + "',"
		+com.fandy.struts.Meta.GoodsInfo.getSize() + "='"  + gi.getSize()+ "',"
		+com.fandy.struts.Meta.GoodsInfo.getType() + "='"  + gi.getType() + "',"
		+com.fandy.struts.Meta.GoodsInfo.getUnit() + "='"  + gi.getUnit() + "'"
		+"where "+com.fandy.struts.Meta.GoodsInfo.getGoodsid()+"="+GoodsID;
				
	}
	
	
	public String DeleteByID(int id)
	{
		
		return "delete from staff where " + com.fandy.struts.Meta.GoodsInfo.getGoodsid() +"="+id;
		
	}
	
	
}
